import 'package:flutter/material.dart';

class LoadBuilder extends StatefulWidget {
  bool visibility;
  bool textVisibility;
  String textTips;
  String textEmptyTips;
  bool emptyVisibility;
  bool emptyTextVisibility;
  final Widget builder;
  final double width;
  final double height;
  final Color bgColor;
  final Color cirColor;
  LoadBuilder({
    Key key,
    this.visibility = false,
    this.textVisibility = false,
    this.emptyVisibility = false,
    this.width = 35,
    this.height = 35,
    this.bgColor = Colors.white,
    this.cirColor = Colors.transparent,
    this.textTips,
    this.textEmptyTips,
    this.emptyTextVisibility=false,
    @required this.builder
  }):
  assert(builder != null),
  super(key:key);

  @override
  State<StatefulWidget> createState() {
    return _LoadBuilder();
  }
}

class _LoadBuilder extends State<LoadBuilder>{
  /*Widget successView;*/
  @override
  Widget build(BuildContext context) {
 /*   print(widget.visibility);
    if(widget.visibility==true){
      successView=Container();
    }else{
      successView=widget.builder;
    }*/
    return Stack(
      children: <Widget>[
        widget.builder,
        Positioned(
          child: Visibility(
            visible: widget.visibility,
            child: Container(
              height: MediaQuery.of(context).size.height,
              color: widget.bgColor,
            ),
          )
        ),
        Positioned(
          child: Visibility(
            visible: widget.visibility,
            child:  Center(child: Column(mainAxisAlignment: MainAxisAlignment.center,children: <Widget>[
              SizedBox(
                height: widget.height,
                width: widget.width,
                child: CircularProgressIndicator(
                  backgroundColor: widget.cirColor,
                ),
              ),
              Visibility(visible: widget.textVisibility,child: Text("${widget.textTips}",style: TextStyle(fontSize: 16),))
            ],),),

          )
        ),
        Positioned(
            child: Visibility(
              visible: widget.emptyVisibility,
              child:  Center(child: Column(mainAxisAlignment: MainAxisAlignment.center,children: <Widget>[
                Image.asset(
                  "assets/images/empty.png",
                  fit: BoxFit.fill,
                  width: 100,
                  height: 80,
                ),
                Visibility(visible: widget.emptyTextVisibility,child: Text("${widget.textEmptyTips}",style: TextStyle(fontSize: 14),))
              ],),),

            )
        ),
      ]
    );
  }

}